/**
 * Description:
 * Class Name:RedirectIn
 * Date:2022/5/2 15:16
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第15章_输入输出._15_5_重定向标准输入输出;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;

public class RedirectIn {
    public static void main(String[] args) {
        String class_path = "./src/" + RedirectIn.class.getName().replace(".", "/") + ".java";
        try (
                var fis = new FileInputStream(class_path)
                ){
            System.setIn(fis);
            // 使用Scanner获取已重定向的标准输入
            var sc = new Scanner(System.in);
            sc.useDelimiter("\n");
            while (sc.hasNext()){
                System.out.println(sc.next());
            }
        }
        catch (IOException ioException){
            ioException.printStackTrace();
        }
    }
}
